<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/7/10 0010
 * Time: 17:10
 */

namespace App\Content\Controllers\Home;

use App\Base\Controllers\Controller;
use App\Content\Contracts\BulletinInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class BulletinController extends Controller
{

    /**
     * 广告接口
     * @return BulletinInterface
     */
    public function getBulletinInterface()
    {
        return app()->make(BulletinInterface::class);
    }

    /**
     * 获取列表
     * @param Request $request
     * @return mixed
     */
    public function getList(Request $request)
    {
        $where = function ($query) use ($request) {
            $sendType = $request->input("send_type", "");
            if(!empty($sendType)){
                $query->whereIn("lid", [0,$sendType]);
            }else{
                $query->whereIn("lid", [0,1]);
            }
            $query->where("status",1);
            //时间限制没放
        };
        return $this->getBulletinInterface()->getList($where);
    }

    /**
     * 获取详情
     * @param Request $request
     */
   public function detail(Request $request){
       $validator = Validator::make($request->all(), [
           'id' => 'required',
       ]);
       if ($validator->fails()) {
           //$error=$validator->errors()->getMessages();
           $this->throwValidatorException($validator);
       }
        $id=$request->input("id");
        return $this->getBulletinInterface()->getInfo($id);
   }

}